<?php

/**
 * contact actions.
 *
 * @package    tld
 * @subpackage contact
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2692 2006-11-15 21:03:55Z fabien $
 */
class myContactFormActions extends sfActions
{
	public function executeIndex($request)
	{
		$this->form = new ContactForm();

		if ($request->isMethod('post'))
		{
			$this->form->bind($request->getParameter('contact'));
			
			if ($this->form->isValid())
			{
				$content = '';
			  foreach($this->form->getValues() as $label=>$value) {
          $content .= $this->form->getWidgetSchema()->getLabel($label).' : '.$value.'\n';
        }
			
			  $mailer = new Swift(new Swift_Connection_NativeMail());
        try
        {
          // Create the mailer and message objects
          $message = new Swift_Message('Demande de devis sur TousLesDevis.fr');

          $message->attach(new Swift_Message_Part($content, 'text/plain'));
          //$mailer->send($message, 'ricardvince@gmail.com', 'contact@sfshopping.fr');
          $mailer->disconnect();
          
          $this->getUser()->setFlash('notice', 'Votre email à bien été envoyé');
        }
        catch (Exception $e)
        {
          $mailer->disconnect();
          // handle errors there
        }
        
        $this->redirect('myContactForm/index');
			}
		}
	}
}
